const path = require("path")
const webpack = require("webpack")
const CopyWebpackPlugin = require("copy-webpack-plugin")

const pgearthBuild = "./node_modules/pg-earth/Build"
const pgearthSource = "./node_modules/pg-earth/Source"
const pgearthExtends = "./node_modules/pg-earth/PGEarthExtends"
const pgearthWorkers = "../Build/Workers"
const assetsPath = "static"
const pgearthStatic = "./pg-earth"

const staticpgearthDir = path.join(assetsPath, pgearthStatic)

module.exports = {
  "configureWebpack": {
    "resolve": {
      "alias": {
        "pgearthSource": path.resolve(__dirname, pgearthSource),
        "pgearthBuild": path.resolve(__dirname, pgearthBuild),
        "pgearthExtends": path.resolve(__dirname, pgearthExtends),
      }
    },
    "output": {
      "sourcePrefix": ""
    },
    "amd": {
      "toUrlUndefined": true
    },
    "plugins": [
      new CopyWebpackPlugin([{
        "from": path.join(pgearthSource, pgearthWorkers),
        "to": path.join(staticpgearthDir, "Workers")
      }, {
        "from": path.join(pgearthBuild, "Assets"),
        "to": path.join(staticpgearthDir, "Assets")
      }, {
        "from": path.join(pgearthBuild, "Widgets"),
        "to": path.join(staticpgearthDir, "Widgets")
      }, {
        "from": path.join(pgearthBuild, "ThirdParty/Workers"),
        "to": path.join(staticpgearthDir, "ThirdParty/Workers")
      }]),
      new webpack.DefinePlugin({
        "PGEARTH_BASE_URL": JSON.stringify(staticpgearthDir),
      })
    ],
    "module": {
      "unknownContextRegExp": /^("|')\.\/.*?\1$/,
      "unknownContextCritical": false
    }
  }
}